package org.zoomdev.zoom.http;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 极简http
 */
public class SimpleHttp {


    protected static HttpClient client;


    public static HttpClient getClient() {
        if (client == null) {
            synchronized (SimpleHttp.class) {
                if (client == null) {
                    client = new DefaultOkHttpClient();
                }
            }
        }
        return client;
    }


    public static Response execute(Request request) throws IOException {
        return getClient().execute(request);
    }


    public static Map<String, String> form(Object... values) {

        Map<String, String> data = new HashMap<>();
        if (values.length % 2 != 0) {
            throw new IllegalArgumentException("参数个数不正确");
        }

        for (int i = 0, c = values.length; i < c; i += 2) {
            data.put(String.valueOf(values[i]), String.valueOf(values[i + 1]));
        }

        return data;

    }
}
